var express = require("express");
var app = express();
app.use("/public", express.static("public"));

//get请求
app.get("/index.html", function(req, res) {
    res.sendFile(public + "/" + "index.htm");
})
app.get("/list", function(req, res) {
        var response = {
            "first_name": req.query.one_name,
            "last_name": req.query.two_name
        };
        console.log(response);

        res.end(JSON.stringify(response));
    })
    //post请求
var bodyParser = require('body-parser');
app.use(bodyParser.json());
var urlencodedParser = bodyParser.urlencoded({ extended: false })
app.post('/list', urlencodedParser, function(req, res) {

    // 输出 JSON 格式
    var response = {
        "first_name": req.query.one_name,
        "last_name": req.query.two_name
    };
    console.log(response);
    res.end(JSON.stringify(response));
})

var server = app.listen(8080, function() {
    var home = hostname = 'http://localhost';
    var host = server.address().address
    var port = server.address().port

    console.log("应用实例，访问地址为  " + home + ":" + port);

})